package com.bristua.mall.user.biz;

import com.bristua.mall.common.utils.CacheUtil;
import com.bristua.mall.user.dao.TUserCollectionMapper;
import com.bristua.mall.user.model.TUser;
import com.bristua.mall.user.model.TUserCollection;
import com.bristua.mall.user.model.condition.TUserCollectionExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2019/5/16.
 */
@Service
@Transactional
public class CancelGoodsCollectionBiz {
    @Resource
    private TUserCollectionMapper tUserCollectionMapper;

    @Autowired
    private CacheUtil cacheUtil;


    public void cancelGoodsCollection(String goodsId){
        TUser userSession = (TUser) cacheUtil.getUserSession();
        TUserCollectionExample tUserCollectionExample = new TUserCollectionExample();
        tUserCollectionExample.createCriteria().andGoodsIdEqualTo(goodsId).andUserIdEqualTo(userSession.getUserId());
        List<TUserCollection> tUserCollections = tUserCollectionMapper.selectByExample(tUserCollectionExample);
        if(tUserCollections!=null && tUserCollections.size()>0){
            TUserCollection tUserCollection = tUserCollections.get(0);
            tUserCollectionMapper.deleteByPrimaryKey(tUserCollection.getUserCollectionId());
        }
    }

}
